package edu.zut.main.thread;

public class ThreadDemo1 {
    public static void main(String[] args) {
        System.out.println("主线程开始");
        //子线程A
        ThreadA threadA = new ThreadA("A");
        //让子线程A处于就绪
        threadA.start();
        System.out.println("主线程结束");
    }

}

//线程创建的第一种方式,继承Thread，重写run
class ThreadA extends Thread{
    /**
     * @param name 线程名称
     */
    public ThreadA(String name){
        super(name);
    }

    //当前线程的执行任务
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+"执行");
            try {
                //让当前线程休眠3s
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}




